package com.oplink.webems.modules.cfg.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.oplink.webems.modules.alarm.entity.AlarmProp;

/**
 * Configuration Card Type Entity
 * @author yizhang
 */
@Entity
@Table(name = "cfg_cardtype")
@DynamicInsert @DynamicUpdate
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class CfgCardType {
	
	private Long id;
	
	private String cardtype;
	
	@JSONField(serialize=false)
	List<CfgCard> cardlist = Lists.newArrayList();
	
	@JSONField(serialize=false)
	List<AlarmProp> aproplist = Lists.newArrayList();

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getCardtype() {
		return cardtype;
	}

	public void setCardtype(String cardtype) {
		this.cardtype = cardtype;
	}

	@OneToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE},fetch=FetchType.LAZY,mappedBy="cardtype")
	@NotFound(action = NotFoundAction.IGNORE)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)	
	@JsonIgnore
	public List<CfgCard> getCardlist() {
		return cardlist;
	}

	public void setCardlist(List<CfgCard> cardlist) {
		this.cardlist = cardlist;
	}

	@OneToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE},fetch=FetchType.LAZY,mappedBy="cardtype")
	@NotFound(action = NotFoundAction.IGNORE)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)	
	@JsonIgnore
	public List<AlarmProp> getAproplist() {
		return aproplist;
	}

	public void setAproplist(List<AlarmProp> aproplist) {
		this.aproplist = aproplist;
	}

}
